home *** CD-ROM | disk | FTP | other *** search
- package
- {
- import flash.display.*;
- import flash.events.*;
- import flash.geom.*;
-
- public class Part extends Bitmap
- {
-
-
- internal var _partTuckIn:Part = null;
-
- internal var _sPose:String;
-
- internal var _bFront:Bitmap = null;
-
- internal var _parttemplate:PartTemplate;
-
- internal var _bBack:Bitmap = null;
-
- public function Part()
- {
- _bFront = null;
- _bBack = null;
- _partTuckIn = null;
- super();
- addEventListener(Event.ADDED_TO_STAGE,onAdded,false,0,true);
- addEventListener(Event.REMOVED_FROM_STAGE,onRemoved,false,0,true);
- }
-
- public function center() : void
- {
- x = -width / 2;
- y = -height / 2;
- }
-
- protected function onRemoved(param1:Event) : void
- {
- if(_bFront != null)
- {
- _bFront.parent.removeChild(_bFront);
- _bFront = null;
- }
- if(_bBack != null)
- {
- _bBack.parent.removeChild(_bBack);
- _bBack = null;
- }
- if(_partTuckIn != null)
- {
- _partTuckIn.parent.removeChild(_partTuckIn);
- _partTuckIn = null;
- alpha = 1;
- }
- }
-
- protected function onAdded(param1:Event) : void
- {
- var _loc2_:Model = null;
- var _loc3_:MovieClip = null;
- var _loc4_:PartTemplate = null;
- if(parent.parent is Model)
- {
- _loc2_ = parent.parent as Model;
- if(Template.HasFront)
- {
- if(_bFront == null)
- {
- _bFront = new Bitmap();
- _loc3_ = _loc2_.getLayers()[Model.NUM_LAYERS - 2] as MovieClip;
- _loc3_.addChild(_bFront);
- adjust(_bFront);
- }
- }
- if(Template.HasBack)
- {
- if(_bBack == null)
- {
- _bBack = new Bitmap();
- _loc3_ = _loc2_.getLayers()[1] as MovieClip;
- _loc3_.addChild(_bBack);
- adjust(_bBack);
- }
- }
- if((_loc4_ = getTuckInTemplate()) != null)
- {
- _partTuckIn = _loc4_.createPart();
- _loc3_ = _loc2_.getLayers()[this.Layer] as MovieClip;
- _loc3_.addChild(_partTuckIn);
- _partTuckIn.x = 0;
- _partTuckIn.y = 0;
- _partTuckIn.alpha = 0;
- }
- Pose = Pose;
- }
- }
-
- public function get Template() : PartTemplate
- {
- return _parttemplate;
- }
-
- public function hasPixel(param1:Number, param2:Number, param3:DisplayObjectContainer) : Boolean
- {
- var _loc4_:Boolean = false;
- var _loc5_:Rectangle = null;
- var _loc6_:int = 0;
- _loc4_ = false;
- if((_loc5_ = getBounds(param3)).containsPoint(new Point(param1,param2)))
- {
- if((_loc6_ = int(bitmapData.getPixel32(param1 - _loc5_.x,param2 - _loc5_.y))) != 0)
- {
- _loc4_ = true;
- }
- else if(_bBack != null)
- {
- if((_loc6_ = int(_bBack.bitmapData.getPixel32(param1 - _loc5_.x,param2 - _loc5_.y))) != 0)
- {
- _loc4_ = true;
- }
- }
- }
- return _loc4_;
- }
-
- public function get Category() : String
- {
- return _parttemplate.Category;
- }
-
- public function set Template(param1:PartTemplate) : *
- {
- _parttemplate = param1;
- Pose = ModelPose.DEFAULT;
- }
-
- public function get Layer() : int
- {
- return _parttemplate.Layer;
- }
-
- public function isEqual(param1:Part) : Boolean
- {
- if(param1 != null)
- {
- if(Template.Name == param1.Template.Name)
- {
- return true;
- }
- }
- return false;
- }
-
- protected function getTuckInTemplate() : PartTemplate
- {
- var _loc1_:* = null;
- _loc1_ = Template.Name + "_VER2";
- return MainDocument.Package.getTemplateByName(_loc1_);
- }
-
- protected function adjust(param1:DisplayObject) : void
- {
- var _loc2_:int = 0;
- _loc2_ = ModelPose.poseToIndex(_sPose,Template.Category);
- param1.x = Template.PoseAdjustments[_loc2_].x;
- param1.y = Template.PoseAdjustments[_loc2_].y;
- }
-
- public function get Pose() : String
- {
- return _sPose;
- }
-
- public function updateTuckIn() : void
- {
- var _loc1_:Model = null;
- var _loc2_:Part = null;
- if(_partTuckIn != null)
- {
- if(parent != null)
- {
- _loc1_ = parent.parent as Model;
- if(_loc1_ != null)
- {
- _loc2_ = null;
- switch(Category)
- {
- case "top":
- _loc2_ = _loc1_.getPart("bottom");
- break;
- case "bottom":
- _loc2_ = _loc1_.getPart("top");
- }
- if(_loc2_ != null && _loc2_.Layer > Layer)
- {
- _partTuckIn.alpha = 1;
- alpha = 0;
- }
- else
- {
- _partTuckIn.alpha = 0;
- alpha = 1;
- }
- }
- else
- {
- _partTuckIn.alpha = 0;
- alpha = 1;
- }
- }
- else
- {
- _partTuckIn.alpha = 0;
- alpha = 1;
- }
- }
- }
-
- public function ResizePart(param1:Number) : void
- {
- if(width > height)
- {
- if(width > param1)
- {
- height = param1 * height / width;
- width = param1;
- }
- }
- else if(height > param1)
- {
- width = param1 * width / height;
- height = param1;
- }
- }
-
- public function set Pose(param1:String) : *
- {
- _sPose = param1;
- this.bitmapData = _parttemplate.getBitmapData(_sPose);
- if(Template.DefaultBitmapProvided && _sPose == ModelPose.DEFAULT)
- {
- x = 0;
- y = 0;
- if(_bFront != null)
- {
- _bFront.visible = false;
- }
- if(_bBack != null)
- {
- _bBack.visible = false;
- }
- }
- else
- {
- adjust(this);
- if(_bFront != null)
- {
- _bFront.bitmapData = _parttemplate.getBitmapDataFront(_sPose);
- _bFront.visible = true;
- adjust(_bFront);
- }
- if(_bBack != null)
- {
- _bBack.bitmapData = _parttemplate.getBitmapDataBack(_sPose);
- _bBack.visible = true;
- adjust(_bBack);
- }
- }
- if(_partTuckIn != null)
- {
- _partTuckIn.Pose = Pose;
- }
- }
- }
- }
-